﻿using MeiWinForms.comm;
using MeiWinForms.communication;

namespace MeiWinForms.module;

public static class Heartbeat
{
    public static async void Heart()
    {
        try
        {
            while (true)
            {
                using var client = new AsyncClient("heartbeat");
                try
                {
                    await client.Connect();
                    Output.WriteOutput("已与服务器建立心跳连接");
                    await client.Send("controller");
                }
                catch (Exception e)
                {
                    Notify.ShowNotification($"已与服务器断连：{e.Message}", "heartbeat");
                }
            }
        }
        catch (Exception e)
        {
            Output.WriteOutput(e.Message);
        }
    }
}